import math

RADIUS = 0.4
CENTER = 0.5
BASE_SPEED = 0.003


def get_pos_by_angle(angle, length_rate=1):
    return CENTER + length_rate * RADIUS * math.cos(math.radians(angle)), CENTER + length_rate * RADIUS * math.sin(
        math.radians(angle))


def get_pos_by_angles(angles):
    res = []
    for angle in angles:
        res.append(get_pos_by_angle(angle))
    return res


def get_ship_angle_by_angle(angle):
    return angle + 180


def get_ship_angle_by_angles(angles):
    res = []
    for angle in angles:
        res.append(get_ship_angle_by_angle(angle))
    return res


def case1():
    return common_case([-90], [90])


def case2():
    agent_ship_infos = [
        {'angle': -90, 'length': 1, 'speed': 4},
    ]
    other_infos = [
        {'angle': -90, 'length': 0.2, 'speed': 2},
    ]
    return special_case(agent_ship_infos, other_infos)


def case3():
    return common_case([-90], [0])


def case4():
    return common_case([-90], [-135])


def case5():
    return common_case([-90], [0, 90])


def case6():
    return common_case([-90], [-45, -75])


def case7():
    agent_ship_infos = [
        {'angle': -90, 'length': 1, 'speed': 4},
    ]
    other_infos = [
        {'angle': -90, 'length': 0.6, 'speed': 2},
        {'angle': -45, 'length': 1, 'speed': 4},
    ]
    return special_case(agent_ship_infos, other_infos)


def case8():
    return common_case([-90], [0, 90])


def case9():
    return common_case([-90], [0, -60])


def case10():
    return common_case([-90], [0, -105])


def case11():
    return common_case([-90], [-60, 180])


def case12():
    return common_case([-90], [-75, -60, 90])


def case13():
    return common_case([-90], [90, -105, -135])


def case14():
    return common_case([-90], [-75, -45, 0])


def case15():
    agent_ship_infos = [
        {'angle': -90, 'length': 1, 'speed': 4},
    ]
    other_infos = [
        {'angle': -90, 'length': 0.6, 'speed': 2},
        {'angle': -45, 'length': 1, 'speed': 4},
        {'angle': 0, 'length': 1, 'speed': 4},
    ]
    return special_case(agent_ship_infos, other_infos)


def case16():
    return common_case([-90], [-135, 0, 180])


def case17():
    agent_ship_infos = [
        {'angle': -90, 'length': 1, 'speed': 4},
    ]
    other_infos = [
        {'angle': -90, 'length': 0.6, 'speed': 2},
        {'angle': -105, 'length': 1, 'speed': 4},
        {'angle': -45, 'length': 1, 'speed': 4},
    ]
    return special_case(agent_ship_infos, other_infos)


def case18():
    return common_case([-90], [-75, -30, 45])


def case19():
    return common_case([-90], [-105, -75, 45])


def case20():
    agent_ship_infos = [
        {'angle': -90, 'length': 1, 'speed': 4},
    ]
    other_infos = [
        {'angle': -90, 'length': 0.6, 'speed': 2},
        {'angle': -75, 'length': 1, 'speed': 4},
        {'angle': 0, 'length': 1, 'speed': 4},
    ]
    return special_case(agent_ship_infos, other_infos)


def case21():
    return common_case([-90], [-105, -75, 0])


def case22():
    agent_ship_infos = [
        {'angle': -90, 'length': 1, 'speed': 4},
    ]
    other_infos = [
        {'angle': -90, 'length': 0.6, 'speed': 2},
        {'angle': -60, 'length': 1, 'speed': 4},
        {'angle': 0, 'length': 1, 'speed': 4},
    ]
    return special_case(agent_ship_infos, other_infos)


def special_case(agent_ship_infos, other_infos):
    """

    :param other_infos: [dict]  [{angle, length, speed}]
    :type agent_ship_infos: [dict]  [{angle, length, speed}]
    """
    agent_ship_pos = [get_pos_by_angle(ship['angle'], ship['length']) for ship in agent_ship_infos]
    agent_ship_target_pos = [get_pos_by_angle(ship['angle'] + 180, ship['length']) for ship in agent_ship_infos]
    agent_ship_angle = [get_ship_angle_by_angle(ship['angle']) for ship in agent_ship_infos]
    agent_ship_speed = [BASE_SPEED * ship['speed'] for ship in agent_ship_infos]

    other_ship_pos = [get_pos_by_angle(ship['angle'], ship['length']) for ship in other_infos]
    other_ship_angle = [get_ship_angle_by_angle(ship['angle']) for ship in other_infos]
    other_ship_speed = [BASE_SPEED * ship['speed'] for ship in other_infos]
    return agent_ship_pos, agent_ship_angle, agent_ship_target_pos, agent_ship_speed, \
           other_ship_pos, other_ship_angle, other_ship_speed


def common_case(agent_ship_angles, other_ship_angles):
    agent_ship_pos = get_pos_by_angles(agent_ship_angles)
    agent_ship_speed = [BASE_SPEED * 4 for _ in agent_ship_angles]
    agent_ship_target_pos = get_pos_by_angles([angle + 180 for angle in agent_ship_angles])
    agent_ship_angle = get_ship_angle_by_angles(agent_ship_angles)

    other_ship_pos = get_pos_by_angles(other_ship_angles)
    other_ship_angle = get_ship_angle_by_angles(other_ship_angles)
    other_ship_speed = [BASE_SPEED * 4 for _ in other_ship_angles]

    return agent_ship_pos, agent_ship_angle, agent_ship_target_pos, agent_ship_speed, \
           other_ship_pos, other_ship_angle, other_ship_speed
